home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / Q-R / R⁄O strsml.cpt / Ratcliff_Obershelp / gestalt.c next >
C/C++ Source or Header  |  1989-01-12  |  1KB  |  47 lines

  1. #include <stdio.h>
  2. #include <strings.h>
  3. /*
  4.     GESTALT.C - written by John W. Ratcliff and David E. Metzener November 10, 1987.
  5.         Demonstrates the Ratcliff/Obershelp Pattern Recognition Algorithm.  Link with
  6.         the Function simil(str1, str2).
  7.         
  8.         (DDJ, July 1988, #141, pg.46-51, 68-72).
  9.  
  10. */
  11. int     simil(char *str1, char *str2);
  12. void ucase(char *str);
  13.  
  14. main()
  15.     {
  16.     char str1[80], str2[80];
  17.     int     prcnt;
  18.     
  19.     printf("This program demonstrates the Ratcliff/Obershelp pattern\n");
  20.     printf("\trecognition algorithm.  Enter a series of word pairs to\n");
  21.     printf("\tdiscover their similarity values.\n\n");
  22.     printf("Enter strings of 'END' and 'END' to exit.\n\n");
  23.     
  24.     do
  25.         {
  26.         printf("Enter two strings seperated by a space:  ");
  27.         scanf("%s %s", str1, str2);
  28.         ucase(str1);
  29.         ucase(str2);
  30.         prcnt = simil(str1, str2);
  31.         printf("%s and %s are %d percent alike.\n\n", str1, str2, prcnt);
  32.         }
  33.     while (strcmp(str1, "END"));
  34.     }
  35.     
  36. /*
  37.     ucase(str) - converts the string to upper case.
  38. */
  39. void    ucase(str)
  40.     char    *str;
  41.     {
  42.     while (*str)
  43.         {
  44.         *str = toupper(*str);
  45.         str++;
  46.         }
  47.     }